<?
include ("../conectar.php"); 
include ("../funciones/fechas.php"); 

$codigo_liq=$_GET["codigo_liq"];
$cadena_busqueda=$_GET["cadena_busqueda"];
$liqNro=$_GET['liqNro'];
$tipoLiqMenu=$_GET['tipoLiqMenu'];

$sel_tipo="SELECT titulo FROM tipo_liquidacion WHERE abreviacion like '$tipoLiqMenu'";
$rs_tipo=mysql_query($sel_tipo);
$titulo=mysql_result($rs_tipo,0,"titulo");

$query="SELECT * FROM liquidacion WHERE codigo_liq='$codigo_liq'";
$rs_query=mysql_query($query);
$fechaLiq=mysql_result($rs_query,0,"fecha_liq");

//list($year, $month, $day) = split('[-.]', $fechaLiq); 
//$fechaLiq = "$day/$month/$year"; 

$fechaLiq = date("d/m/Y",strtotime($fechaLiq));
?>

<html>
	<head>
		<title>Principal</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<link href="../calendario/calendar-blue.css" rel="stylesheet" type="text/css">
		<script type="text/JavaScript" language="javascript" src="../calendario/calendar.js"></script>
		<script type="text/JavaScript" language="javascript" src="../calendario/lang/calendar-sp.js"></script>
		<script type="text/JavaScript" language="javascript" src="../calendario/calendar-setup.js"></script>
		<script type="text/javascript" language="javascript" src="../funciones/tabla.js"></script>
		<script type="text/javascript" language="javascript" src="../funciones/calculos.js"></script>				
		<script language="javascript">
		var cursor;
		if (document.all) {
		// Está utilizando EXPLORER
		cursor='hand';
		} else {
		// Está utilizando MOZILLA/NETSCAPE
		cursor='pointer';
		}
		
		var miPopup
		function abreVentana(obj){
			var tab=obj.parentNode.parentNode.parentNode.parentNode.id;//id de la tabla			
			//iniciarTabla(tab);	
			//inicia2();
			miPopup = window.open("ver_clientes2.php","miwin","width=700,height=380,scrollbars=yes");
			miPopup.focus();
		}
		
		function ventanaArticulos(){
			var codigo=document.getElementById("codcliente").value;
			if (codigo=="") {
				alert ("Debe introducir el codigo del cliente");
			} else {
				miPopup = window.open("ver_articulos.php","miwin","width=700,height=500,scrollbars=yes");
				miPopup.focus();
			}
		}

		function ventanaConceptos(celda){
			
			tab=celda.parentNode.parentNode.parentNode;

			miPopup = window.open("ver_conceptos.php?fila="+celda.parentNode.rowIndex+"&columna="+celda.cellIndex+"&tab="+tab.id,"miwin","width=700,height=600,scrollbars=no");
			miPopup.focus();
		}

		function ventanaConceptosDato(celda){
			
			tab=celda.parentNode.parentNode.parentNode;

			miPopup = window.open("ver_conceptosDatos.php?fila="+celda.parentNode.rowIndex+"&columna="+celda.cellIndex+"&tab="+tab.id,"miwin","width=700,height=600,scrollbars=no");
			miPopup.focus();
		}
		
		function validarcliente(){			
			var codigo=document.getElementById("nombre").value;
			miPopup = window.open("comprobarcliente.php?codcliente="+codigo,"frame_datos","width=700,height=80,scrollbars=yes");
		}	
		
		function cancelar() {
			var tipo=document.getElementById('tipoLiq').value;
			location.href="index.php?tipo="+tipo;
		}
		
		function limpiarcaja() {
			document.getElementById("nombre").value="";
			document.getElementById("ruc").value="";
		}
		
		function elegir_plantilla()
		{
			var valor=document.getElementById("cboPlantillas").value;
			//copiar el codigo de la plantilla
			//document.getElementById("pe").value=valor;
		}

		function verPlantilla(){						
			miPopup = window.open("ventana_plantilla.php","miwin","width=700,height=380,scrollbars=yes");
			miPopup.focus();
		}

		function validar_soloNum(field)
		{
			//var regExpr = new RegExp("^\d*\.?\d*$");
			var regExpr = new RegExp("^\d+");
			if (regExpr.test(field.value)) 
			{
			      // Case of error
			      field.value = "";
			}
			alert(field.value);

		}


		function actualizar_importe()
			{
				var precio=document.getElementById("precio").value;
				var cantidad=document.getElementById("cantidad").value;
				var descuento=document.getElementById("descuento").value;
				descuento=descuento/100;
				total=precio*cantidad;
				descuento=total*descuento;
				total=total-descuento;
				var original=parseFloat(total);
				var result=Math.round(original*100)/100 ;
				document.getElementById("importe").value=result;
			}
			
		function validar_cabecera()
		{
			var mensaje="";
			if (document.getElementById("nombre").value=="") 
				mensaje+="Ningun Cliente asignado!\n";

			if (document.getElementById("total").value=="" || document.getElementById("total").value==0) 
				mensaje+="El total no puede estar vacio o ser cero!\n";
				
			if (mensaje!="") {
				alert("Atencion, se han detectado las siguientes incorrecciones:\n\n"+mensaje);
			} 
			else 
			{					
				grabar_liq();

				//copiar otros datos de los otros formularios
				document.getElementById('cliente_liq').value=document.getElementById('nombre').value;
				document.getElementById('importe_total_liq').value=document.getElementById('total').value;				
				
				document.getElementById("formulario").submit();
			}
				
		}	
		
		function validar() 
			{
				var mensaje="";
				var entero=0;
				var enteroo=0;
		
				if (document.getElementById("referencia").value=="") mensaje="  - Referencia\n";
				if (document.getElementById("descripcion").value=="") mensaje+="  - Descripcion\n";
				if (document.getElementById("precio").value=="") { 
							mensaje+="  - Falta el precio\n"; 
						} else {
							if (isNaN(document.getElementById("precio").value)==true) {
								mensaje+="  - El precio debe ser numerico\n";
							}
						}
				if (document.getElementById("cantidad").value=="") 
						{ 
						mensaje+="  - Falta la cantidad\n";
						} else {
							enteroo=parseInt(document.getElementById("cantidad").value);
							if (isNaN(enteroo)==true) {
								mensaje+="  - La cantidad debe ser numerica\n";
							} else {
									document.getElementById("cantidad").value=enteroo;
								}
						}
				if (document.getElementById("descuento").value=="") 
						{ 
						document.getElementById("descuento").value=0 
						} else {
							entero=parseInt(document.getElementById("descuento").value);
							if (isNaN(entero)==true) {
								mensaje+="  - El descuento debe ser numerico\n";
							} else {
								document.getElementById("descuento").value=entero;
							}
						} 
				if (document.getElementById("importe").value=="") mensaje+="  - Falta el importe\n";
				
				if (mensaje!="") {
					alert("Atencion, se han detectado las siguientes incorrecciones:\n\n"+mensaje);
				} else {
					document.getElementById("baseimponible").value=parseFloat(document.getElementById("baseimponible").value) + parseFloat(document.getElementById("importe").value);	
					cambio_iva();
					document.getElementById("formulario_lineas").submit();
					document.getElementById("referencia").value="";
					document.getElementById("descripcion").value="";
					document.getElementById("precio").value="";
					document.getElementById("cantidad").value=1;
					document.getElementById("importe").value="";
					document.getElementById("descuento").value=0;						
				}
			}

		function validar2() 
		{
			var mensaje="";

			if (document.getElementById("descripcion").value=="") mensaje+="  - Descripcion\n";
			if (document.getElementById("importe").value=="") mensaje+="  - Falta el importe\n";
			
			if (mensaje!="") {
				alert("Atencion, se han detectado las siguientes incorrecciones:\n\n"+mensaje);
			} else {
				document.getElementById("formulario_lineas").submit();
				document.getElementById("descripcion").value="";
				document.getElementById("importe").value="";					
			}
		}
			
		function cambio_iva() {
			var original=parseFloat(document.getElementById("baseimponible").value);
			var result=Math.round(original*100)/100 ;
			document.getElementById("baseimponible").value=result;
	
			document.getElementById("baseimpuestos").value=parseFloat(result * parseFloat(document.getElementById("iva").value / 100));
			var original1=parseFloat(document.getElementById("baseimpuestos").value);
			var result1=Math.round(original1*100)/100 ;
			document.getElementById("baseimpuestos").value=result1;
			var original2=parseFloat(result + result1);
			var result2=Math.round(original2*100)/100 ;
			document.getElementById("preciototal").value=result2;
		}	

		</script>
	</head>
	<body onLoad=inicia2()>
		<div id="pagina">
			<div id="zonaContenido">								
				<div align="center">	
				<div id="botonBusqueda">					
						<div align="left">
							<img src="../img/botonaceptar.jpg" width="85" height="22" onClick="validar_cabecera()" border="1" onMouseOver="style.cursor=cursor">
							<img src="../img/botoncancelar.jpg" width="85" height="22" onClick="cancelar()" border="1" onMouseOver="style.cursor=cursor">					
						</div>
			      	</div>				
				<div id="tituloForm2" class="header">MODIFICAR LIQUIDACION <?echo $titulo?></div>				
				<div id="frmBusqueda2">					
					<form id="formulario" name="formulario" method="post" action="guardar_liquidacion.php">
						<input type="hidden" id="tipoLiq" name="tipoLiq" value="<?echo $tipoLiqMenu?>">
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabCab" minimo=1 columnas=5 nrot=0>
						</tr>						
						<tr>
							<td width="5%">&nbsp;</td>								
							<td width="20%">Fecha</td>
							<td width="32%"><input name="fecha" type="text" class="cajaMedia" id="fecha" size="10" maxlength="10" value="<? echo $fechaLiq?>" > <img src="../img/calendario.png" name="Image1" id="Image1" width="16" height="16" border="0" id="Image1" onMouseOver="this.style.cursor='pointer'">
							<script type="text/javascript">
								Calendar.setup(
								  {
								inputField : "fecha",
								ifFormat   : "%d/%m/%Y",
								button     : "Image1"
								  }
								);
							</script></td>	
							<td width="20%">LIQUIDACION</td>
						    	<td width="20%"><input name="liq_nro" type="text" class="cajaMedia" id="liq_nro" disabled="disabled" value="<?echo $liqNro?>"></td>					
						</tr>																		
						</table>								
						<input id="accion" name="accion" value="modificar" type="hidden">
						<input id="tablasCont" name="tablasCont" type="hidden">
						<input id="liqTipo" name="liqTipo" type="hidden" value="<?echo $tipoLiqMenu?>">
						<input id="liqNro2" name="liqNro2" type="hidden" value="<?echo $liqNro?>">
						<input id="cliente_liq" name="cliente_liq" type="hidden">																										
						<input id="importe_total_liq" name="importe_total_liq" type="hidden">
						<input id="codigo_liq" name="codigo_liq" type="hidden" value="<?echo $codigo_liq?>">																																																		
					</form><!--Fin de formulario1-->
				</div><!--Fin de Busqueda2-->				
				<br/>	
				<div id="tituloForm2" class="header">Datos</div>
				<div id="frmBusqueda2">								
					<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabDatos" minimo=3 columnas=5 nrot=1>							
					<form id="formulario_datos" name="formulario_datos" method="post" action="guardar_factura.php">						
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='1' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array(); //registro con cada valor para celda
						$registro_tipo=array(); //registro con cada tipo dependiendo del valor
						$nrof=0; //nro de filas
						$contfech=0; //contador de fechas
						if($cant>0){?>							
							<?
							for ($i = 0; $i < $cant; $i++) 
							{ 
								$fila=mysql_result($rs_lineas,$i,"fila_liq");
								$columna=mysql_result($rs_lineas,$i,"columna_liq");
								$valor=mysql_result($rs_lineas,$i,"valor_liq");																								

								//Seleccionar el tipo de concepto de la tabla conceptos
								$sel="SELECT count(*) as c FROM conceptos WHERE descripcion like '$valor'";
								$rs=mysql_query($sel) or die(mysql_error());
								$c=mysql_result($rs,0,"c");
								if($c>0)
								{
									$sel="SELECT tipo FROM conceptos WHERE descripcion like '$valor'";
									$rs=mysql_query($sel) or die(mysql_error());
									$tipoc=mysql_result($rs,0,"tipo"); //tipo de concepto, alfanumerico o numerico
									
								}
										
								if($fila==$nrof)
								{
									$registro[$columna-1]=$valor;	
									$registro_tipo[$columna-1]=$tipoc;																
								}
								else
								{	
									//echo $registro[0].",".$registro[1].",".$registro[2].",".$registro[3]."<br>";

									$i--;
								?>
									<tr>												
									<?if ($nrof<2){?>
										<td width="5%">&nbsp;</td>	
										<td width="20%"><?echo $registro[0]?></td>
									<?}
									else{?>
										<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>															
										<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>								
									<?}?>

									<?if($fila==1){?>
										<td witdh="32%" id="celda"><input name="nombre" type="text" class="cajaCliente" id="nombre" value="<?echo $registro[1]?>"> <img id="img1" src="../img/ver.png" width="16" height="16" onClick="abreVentana(this)" title="Buscar cliente" onMouseOver="style.cursor=cursor"> <img src="../img/cliente.png" width="16" height="16" onClick="validarcliente()" title="Validar cliente" onMouseOver="style.cursor=cursor"></td>																	
									<?}else{
										if($fila==2){?>
											<td witdh="32%" id="celda"><input name="ruc" type="text" class="cajaMedia" id="ruc" value="<?echo $registro[1]?>"></td>																	
										<?}else{
											$regCelda=strtoupper($registro[0]);
											if($regCelda=='FECHA'){
												$contfech++;?>
												<td width="32%" ><input NAME="fecha<?echo $contfech?>" type="text" class="cajaPequena" id="fecha<?echo $contfech?>" size="10" maxlength="10" value="<? echo $registro[1]?>" > <img src="../img/calendario.png" name="ImageC<?echo $contfech?>" id="ImageC<?echo $contfech?>" width="16" height="16" border="0" onMouseOver="this.style.cursor='pointer'" onClick="elegirCalendario(this)"></td>	
											<?}else{
												if($regCelda=='REGIMEN ADUANERO'){?>
													<td width="32%"><input type="text" class="cajaCliente" size="50" maxlength="50" value="<?echo $registro[1]?>"></td>	
												<?}else{?>
													<td width="32%"><input type="text" class="cajaCliente" size="50" maxlength="50" value="<?echo $registro[1]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptosDato(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar datos conceptos"></td>														
												<?}
											}							
										}
									}?>
									<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>																
									<?									
									$fecha=strtoupper($registro[2]);
									if($fecha=='FECHA'){
										$contfech++;?>
										<td width="20%" ><input NAME="fecha<?echo $contfech?>" type="text" class="cajaPequena" id="fecha<?echo $contfech?>" size="10" maxlength="10" value="<? echo $registro[3]?>" > <img src="../img/calendario.png" name="ImageC<?echo $contfech?>" id="ImageC<?echo $contfech?>" width="16" height="16" border="0" onMouseOver="this.style.cursor='pointer'" onClick="elegirCalendario(this)"></td>	
									<?}else{										
										if($registro_tipo[2]=='A'){?>
											<td width="20%"><input type="text" class="cajaMedia" size="20" maxlength="20" value="<?echo $registro[3]?>" style="text-align:right"></td>																					
										<?}else{
											$subCelda=strtoupper(substr($registro[2],0,15));
											if($subCelda=="VALOR IMPONIBLE"){?>
												<td width="20%"><input type="text" class="cajaMedia" size="20" maxlength="20" value="<?echo $registro[3]?>" onfocus="calculaValorImponible(this)" readonly style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
											<?}else{?>
												<td width="20%"><input type="text" class="cajaMedia" size="20" maxlength="20" value="<?echo $registro[3]?>" onkeyup="calculaDatos(this)" onfocus="calculaDatos(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
											<?}
										}							
									}?>
								</tr>
								<?
									$nrof++;								
									for($x=0;$x<4;$x++)													
										$registro[$x]="";	

								}
							}
							?>								
							<!--Para imprimir la ultima fila-->
							<tr>
								<?if ($nrof<2){?>
									<td width="5%">&nbsp;</td>	
									<td width="20%"><?echo $registro[0]?></td>
								<?}
								else{?>
									<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>															
									<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>								
								<?}
								$regCelda=strtoupper($registro[0]);
								if($regCelda=='FECHA'){
									$contfech++;?>
									<td width="32%"><input NAME="fecha<?echo $contfech?>" type="text" class="cajaPequena" id="fecha<?echo $contfech?>" size="10" maxlength="10" value="<? echo $registro[1]?>" > <img src="../img/calendario.png" name="ImageC<?echo $contfech?>" id="ImageC<?echo $contfech?>" width="16" height="16" border="0" onMouseOver="this.style.cursor='pointer'" onClick="elegirCalendario(this)"></td>	
								<?}else{
									if($regCelda=='REGIMEN ADUANERO'){?>
										<td width="32%"><input type="text" class="cajaCliente" size="50" maxlength="50" value="<?echo $registro[1]?>"></td>	
									<?}else{?>										
										<td width="32%"><input type="text" class="cajaCliente" size="50" maxlength="50" value="<?echo $registro[1]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptosDato(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar datos conceptos"></td>										
									<?}
								}?>
								<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>								
								<?																	
								$regCelda=strtoupper($registro[2]);
								if($regCelda=='FECHA'){
									$contfech++;?>
									<td width="20%"><input name="fecha<?echo $contfech?>" type="text" class="cajaPequena" id="fecha<?echo $contfech?>" size="10" maxlength="10" value="<? echo $registro[3]?>" > <img src="../img/calendario.png" name="ImageC<?echo $contfech?>" id="ImageC<?echo $contfech?>" width="16" height="16" border="0" onMouseOver="this.style.cursor='pointer'" onClick="elegirCalendario(this)"></td>	
								<?}else{
									if($registro_tipo[2]=='A'){?>
										<td width="20%"><input type="text" class="cajaMedia" size="20" maxlength="20" value="<?echo $registro[3]?>" style="text-align:right"></td>																					
									<?}else{
										$subCelda=strtoupper(substr($registro[2],0,15));
										if($subCelda=="VALOR IMPONIBLE"){?>
											<td width="20%"><input type="text" class="cajaMedia" size="20" value="<?echo $registro[3]?>" maxlength="20" onfocus="calculaValorImponible(this)" readonly style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}else{?>
											<td width="20%"><input type="text" class="cajaMedia" size="20" value="<?echo $registro[3]?>" maxlength="20" onkeyup="calculaDatos(this)" onfocus="calculaDatos(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>								
										<?}
									}
								}?>								
							</tr>	
							<!--En el caso que tenga solo Cliente y RUC como filas-->
							<?if($nrof==1){?>
							<tr>
								<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>															
								<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>								
								<td witdh="32%" id="celda"><input name="nombre" type="text" class="cajaCliente" id="nombre" value="<?echo $registro[1]?>"></td>																										
								<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>								
								<td width="20%"><input type="text" class="cajaMedia" value="<?echo $registro[3]?>" ></td>								
							</tr>	
							<?}
						}//fin de cant?>		
					</table>
					</form>	
				</div><!--Fin de Busqueda2-->	
				<br/>
				<div id="frmBusqueda2">		
					<form id="formulario_lineas1" name="formulario_lineas1" method="post" action="frame_lineas.php" target="frame_lineas">					
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabObsDatos" minimo=1 columnas=1 nrot=2>							
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='2' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas
						if($cant>0){
							$fila=mysql_result($rs_lineas,0,"fila_liq");
							$columna=mysql_result($rs_lineas,0,"columna_liq");
							$valor=mysql_result($rs_lineas,0,"valor_liq");																								
													
						}?>					
						<tr>
							<td width="1%">&nbsp;</td>	
							<td width="99%"><b>Observaciones</b></td>								
						</tr>
						<tr>	
							<td width="1%">&nbsp;</td>								
							<?if($cant==0){?>
								<td width="99%"><textarea name="descDatos" id="descDatos" class="areatexto" rows="4" cols="130" wrap="virtual"></textarea></td>
							<?}else{?>				
								<td width="99%"><textarea name="descDatos" id="descDatos" class="areatexto" rows="4" cols="130" wrap="virtual"><?echo $valor?></textarea></td>		
							<?}?>		
						</tr>	
					</table>	
					</form><!--Fin de formulario_lineas-->
				</div><!--Fin de Busqueda2-->
				<br/>
				<div align="center">
				<div id="tituloForm2" class="header">Aduana</div>
				<div id="frmBusqueda3">
					<form id="formulario_lineas" name="formulario_lineas" method="post" action="frame_lineas2.php">
					<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabAduana" minimo=3 columnas=3 nrot=3>						
						<!--<tr class="cabeceraTabla">
							<td width="5%">&nbsp;</td>
							<td width="55%">DESCRIPCION</td>
							<td width="20%">LIBERADO</td>
							<td width="20%">TRIBUTADO</td>
						</tr>-->
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='3' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas

						$sel2="SELECT count(cod_liq) as col FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='3' AND fila_liq=1 ORDER BY fila_liq,columna_liq ASC";
						$rs2=mysql_query($sel2) or die(mysql_error());
						$col=mysql_result($rs2,0,"col");
						//echo "Columnas: ".$col."</br>";

						if($col>0){?>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<?for($cc=0;$cc < $col-1;$cc++){?>
								      <td>&nbsp;<img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar columna" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar columna" onMouseOver="style.cursor=cursor"></td>
								      <!--<td>&nbsp;</td>-->
								<?}?>
							</tr>
						<?}else{?>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>

							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>DESCRIPCION</td>
								<td>Liberado</td>
								<td>Tributado</td>
							</tr>
						<?}
						if($cant>0){?>																				
							<?for ($i = 0; $i < $cant; $i++) { 
								$fila=mysql_result($rs_lineas,$i,"fila_liq");
								$columna=mysql_result($rs_lineas,$i,"columna_liq");
								$valor=mysql_result($rs_lineas,$i,"valor_liq");																								

								//Seleccionar el tipo de concepto de la tabla conceptos
								$sel="SELECT count(*) as c FROM conceptos WHERE descripcion like '$valor'";
								$rs=mysql_query($sel) or die(mysql_error());
								$c=mysql_result($rs,0,"c");
								if($c>0)
								{
									$sel="SELECT tipo FROM conceptos WHERE descripcion like '$valor'";
									$rs=mysql_query($sel) or die(mysql_error());
									$tipoc=mysql_result($rs,0,"tipo"); //tipo de concepto, alfanumerico o numerico									
								}
								else
									$tipoc="";
							
								if($fila==$nrof)
								{
									/*  si tipoc es numerico, realizar conversion de miles, decimales
									if($tipoc=='N')
									*/	
									$registro[$columna-1]=$valor;					
									
								}
								else
								{	
									$i--;
									if($fila==2){?>										
										<tr class="cabeceraTabla">											
											<td width="5%">&nbsp;</td>
											<?for($cc=0;$cc < $col;$cc++){?>
											      <td><?echo $registro[$cc]?></td>
											<?}?>
										</tr>
									<?}else{?>
										<tr>						
											<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
											<?for($cc=0;$cc < $col;$cc++){
												if($cc==0){?>				
													<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[$cc]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
												<?}else{
													if($cc!=($col-1)){?>
														<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
													<?}else{?>
														<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
													<?}
												}
											}?>
										</tr>

									<?}?>
									<!--								
									<tr>										
										<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
										<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
										<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[1]?>" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
									</tr>
									-->
									
								<?
									$nrof++;								
									for($x=0;$x<4;$x++)													
										$registro[$x]="";	

								}
							}
							?>									
						<?}?>
						<!--Para imprimir la ultima fila-->
						<tr>						
							<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
							<?for($cc=0;$cc < $col;$cc++){

								if($cc==0){?>				
									<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[$cc]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
								<?}else{
									if($cc!=($col-1)){?>
										<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
									<?}else{?>
										<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
									<?}
								}
							}?>
						</tr>

						<!--
						<tr>						
							<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>															
							<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
							<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[1]?>" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
							<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>									
						</tr>-->
					</table>	
					</form><!--Fin de formulario2-->
				</div><!--Fin de Busqueda2-->
				<br/>
				<div id="frmBusqueda2">
					<form id="formulario_lineas2" name="formulario_lineas2" method="post">					
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabObsAduana" minimo=1 columnas=1 nrot=4>
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='4' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas
						if($cant>0){
							$fila=mysql_result($rs_lineas,0,"fila_liq");
							$columna=mysql_result($rs_lineas,0,"columna_liq");
							$valor=mysql_result($rs_lineas,0,"valor_liq");																								
						}?>
						<tr>
							<td width="1%">&nbsp;</td>
							<td width="99%"><b>Observaciones</b></td>								
						</tr>
						<tr>	
							<td width="1%">&nbsp;</td>								
							<?if($cant==0){?>
								<td width="99%"><textarea name="descAduana" id="descAduana" class="areatexto" rows="4" cols="130" wrap="virtual"></textarea></td>
							<?}else{?>							
								<td width="99%"><textarea name="descAduana" id="descAduana" class="areatexto" rows="4" cols="130" wrap="virtual"><?echo $valor?></textarea></td>		
							<?}?>		
						</tr>
					</table>	
					</form><!--Fin de formulario_lineas2-->
				</div><!--Fin de Busqueda2-->
				</br>
				<div id="tituloForm2" class="header">Otros Gastos</div>
				<div id="frmBusqueda2">
					<form id="formulario_lineas4" name="formulario_lineas4" method="post">
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabOtros" minimo=3 columnas=4 nrot=7>							
							<!--
							<tr class="cabeceraTabla">
								<td width="5%">&nbsp;</td>
								<td width="55%">DESCRIPCION</td>
								<td width="20%">&nbsp;</td>
								<td width="20%">IMPORTE</td>								
							</tr>						
							-->
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='7' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas

						$sel2="SELECT count(cod_liq) as col FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='7' AND fila_liq=1 ORDER BY fila_liq,columna_liq ASC";
						$rs2=mysql_query($sel2) or die(mysql_error());
						$col=mysql_result($rs2,0,"col");

						if($col>0){?>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<?for($cc=0;$cc < $col-1;$cc++){?>
								      <td>&nbsp;<img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar columna" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar columna" onMouseOver="style.cursor=cursor"></td>
								      <!--<td>&nbsp;</td>-->
								<?}?>
							</tr>
						<?}else{?>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>DESCRIPCION2</td>
								<td>&nbsp;</td>
								<td>IMPORTE2</td>
							</tr>
						<?}
						if($cant>0){?>									
							<?for ($i = 0; $i < $cant; $i++) { 
								$fila=mysql_result($rs_lineas,$i,"fila_liq");
								$columna=mysql_result($rs_lineas,$i,"columna_liq");
								$valor=mysql_result($rs_lineas,$i,"valor_liq");																								
								//echo "cant: ".$cant." i: ".$i."</br>";
								if($fila==$nrof)
								{
									$registro[$columna-1]=$valor;									
								}
								else
								{	
									$i--;
									//echo "fila: ".$fila."</br>";
									if($fila==2){?>										
										<tr class="cabeceraTabla">											
											<td width="5%">&nbsp;</td>
											<?for($cc=0;$cc < $col;$cc++){?>
											      <td><?echo $registro[$cc]?></td>
											<?}?>
										</tr>
									<?}else{?>
										<tr>						
											<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
											<?for($cc=0;$cc < $col;$cc++){

												if($cc==0){?>				
													<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[$cc]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
												<?}else{
													if($cc!=($col-1)){?>
														<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
													<?}else{?>
														<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
													<?}
												}
											}?>
										</tr>

									<?}?>						
									<tr>										
										<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>														
										<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
										<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[1]?>" onkeyup="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>								
										<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>																												
									</tr>
								<?
									$nrof++;								
									for($x=0;$x<4;$x++)													
										$registro[$x]="";	

								}
							}
							?>	
								
						<?}?>
						<!--Para imprimir la ultima fila-->
						<?if($fila==1){?>										
							<tr class="cabeceraTabla">											
								<td width="5%">&nbsp;</td>
								<?for($cc=0;$cc < $col;$cc++){?>
								      <td><?echo $registro[$cc]?></td>
								<?}?>
							</tr>
							<tr>						
								<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
								<?for($cc=0;$cc < $col;$cc++){
									if($cc==0){?>				
										<td witdh="55%"><input type="text" class="cajaGrande2"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
									<?}else{
										if($cc!=($col-1)){?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}else{?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}
									}
								}?>
							</tr>
						<?}else{?>
							<tr>						
								<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
								<?for($cc=0;$cc < $col;$cc++){
									if($cc==0){?>				
										<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[$cc]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
									<?}else{
										if($cc!=($col-1)){?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="miles(this)" onfocus="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}else{?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}
									}
								}?>
							</tr>
						<?}?>
						<!--
						<tr>										
							<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>														
							<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
							<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[1]?>" onkeyup="miles(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>								
							<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[2]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>																												
						</tr>
						-->
					</table>
					</form>
				</div><!--Fin frmBusqueda2--> 
				<br/>
				<div id="frmBusqueda2">
					<form id="formulario_lineas1" name="formulario_lineas1" method="post" action="frame_lineas.php" target="frame_lineas">					
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabObsOtros" minimo=1 columnas=1 nrot=8>
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='8' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas
						if($cant>0){
							$fila=mysql_result($rs_lineas,0,"fila_liq");
							$columna=mysql_result($rs_lineas,0,"columna_liq");
							$valor=mysql_result($rs_lineas,0,"valor_liq");																																																																			
						}?>
						<tr>
							<td width="1%">&nbsp;</td>
							<td width="99%"><b>Observaciones</b></td>								
						</tr>
						<tr>	
							<td width="1%">&nbsp;</td>							
							<?if($cant==0){?>
								<td width="99%"><textarea name="descOtros" id="descOtros" class="areatexto" rows="4" cols="130" wrap="virtual"></textarea></td>		
							<?}else{?>
								<td width="99%"><textarea name="descOtros" id="descOtros" class="areatexto" rows="4" cols="130" wrap="virtual"><?echo $valor?></textarea></td>		
							<?}?>
						</tr>
					</table>	
					</form><!--Fin de formulario_lineas-->
				</div><!--Fin de Busqueda2-->	
				<br/>
				<div align="center">
				<div id="tituloForm2" class="header">Despachante</div>						  
				<div id="frmBusqueda2">
					<form id="formulario_lineas3" name="formulario_lineas3" method="post">					
					<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabDespacho" minimo=3 columnas=4 nrot=5>							
						<!--
						<tr class="cabeceraTabla">
							<td width="5%">&nbsp;</td>
							<td width="55%">DESCRIPCION</td>
							<td width="20%">&nbsp;</td>
							<td width="20%">IMPORTE</td>								
						</tr>
						-->
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='5' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas

						$sel2="SELECT count(cod_liq) as col FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='5' AND fila_liq=1 ORDER BY fila_liq,columna_liq ASC";
						$rs2=mysql_query($sel2) or die(mysql_error());
						$col=mysql_result($rs2,0,"col");

						if($col>0){?>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<?for($cc=0;$cc < $col-1;$cc++){?>
								      <td>&nbsp;<img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar columna" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar columna" onMouseOver="style.cursor=cursor"></td>
								      <!--<td>&nbsp;</td>-->
								<?}?>
							</tr>
						<?}else{?>
							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>

							<tr class="cabeceraTabla">
								<td>&nbsp;</td>
								<td>DESCRIPCION</td>
								<td>&nbsp;</td>
								<td>IMPORTE</td>
							</tr>
						<?}

						if($cant>0){?>								
							<?for ($i = 0; $i < $cant; $i++) { 
								$fila=mysql_result($rs_lineas,$i,"fila_liq");
								$columna=mysql_result($rs_lineas,$i,"columna_liq");
								$valor=mysql_result($rs_lineas,$i,"valor_liq");																								
							
								if($fila==$nrof)
								{
									$registro[$columna-1]=$valor;
								}
								else
								{	
									$i--;
									if($fila==2){?>										
										<tr class="cabeceraTabla">											
											<td width="5%">&nbsp;</td>
											<?for($cc=0;$cc < $col;$cc++){?>
											      <td><?echo $registro[$cc]?></td>
											<?}?>
										</tr>
									<?}else{?>
										<tr>						
											<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
											<?for($cc=0;$cc < $col;$cc++){

												if($cc==0){?>				
													<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[$cc]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
												<?}else{
													if($cc!=($col-1)){?>
														<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onfocus="calculaHonorario(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
													<?}else{?>
														<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
													<?}
												}
											}?>
										</tr>
									<?}?>

									<!--
									<tr>										
										<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>														
										<td witdh="55%"><input name="descripcion" type="text" id="descripcion" class="cajaGrande2" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
										<?$regCelda=substr(strtoupper($registro[0]),0,3);
										if($regCelda=='IVA'){?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" size="15" maxlength="15" value="<?echo $registro[1]?>" readonly style="text-align:right"></td>
										<?}else{?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" size="15" maxlength="15" value="<?echo $registro[1]?>" onfocus="calculaHonorario(this)" readonly style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>								
										<?}?>
										<td width="20%" align="left"><input name="nombre3" type="text" id="nombre3" class="cajaMedia" value="<?echo $registro[2]?>" onfocus="calculaTotal(this)" readonly style="text-align:right"></td>									
									</tr>
									-->
								<?
									$nrof++;								
									for($x=0;$x<4;$x++)													
										$registro[$x]="";	

								}
							}
							?>								
						<?}?>
						<!--Para imprimir la ultima fila-->
						<?if($fila==1){?>										
							<tr class="cabeceraTabla">											
								<td width="5%">&nbsp;</td>
								<?for($cc=0;$cc < $col;$cc++){?>
								      <td><?echo $registro[$cc]?></td>
								<?}?>
							</tr>
							<tr>						
								<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
								<?for($cc=0;$cc < $col;$cc++){
									if($cc==0){?>				
										<td witdh="55%"><input type="text" class="cajaGrande2"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
									<?}else{
										if($cc!=($col-1)){?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" onfocus="calculaHonorario(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}else{?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}
									}
								}?>
							</tr>
						<?}else{?>
							<tr>						
								<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>
								<?for($cc=0;$cc < $col;$cc++){
									if($cc==0){?>				
										<td witdh="55%"><input type="text" class="cajaGrande2" value="<?echo $registro[$cc]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
									<?}else{
										if($cc!=($col-1)){?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onfocus="calculaHonorario(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}else{?>
											<td width="20%" align="left"><input type="text" class="cajaMedia" value="<?echo $registro[$cc]?>" onkeyup="calculaTotal(this)" onfocus="calculaTotal(this)" style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
										<?}
									}
								}?>
							</tr>
						<?}?>

						<!--
						<tr>										
							<td width="5%"><img src="../img/agregar.png" width="16" height="16" title="Agregar datos" alt="agregar fila" onMouseOver="style.cursor=cursor"> <img src="../img/remover.png" width="16" height="16" title="Quitar datos" alt="borrar fila" onMouseOver="style.cursor=cursor"></td>														
							<td witdh="55%"><input name="descripcion" type="text" id="descripcion" class="cajaGrande2" value="<?echo $registro[0]?>"> <img src="../img/ver.png" width="16" height="16" onClick="ventanaConceptos(this.parentNode)" onMouseOver="style.cursor=cursor" title="Buscar conceptos"></td>
							<?if($regCelda=='IVA'){?>
								<td width="20%" align="left"><input type="text" class="cajaMedia" size="15" maxlength="15" value="<?echo $registro[1]?>" readonly style="text-align:right"></td>
							<?}else{?>
								<td width="20%" align="left"><input type="text" class="cajaMedia" size="15" maxlength="15" value="<?echo $registro[1]?>" onfocus="calculaHonorario(this)" readonly style="text-align:right"> <img src="../img/calculadora2.png" width="16" height="16" onMouseOver="style.cursor=cursor" title="Calcular" onclick="calculadora(this.parentNode)"></td>
							<?}?>
							<td width="20%" align="left"><input name="nombre3" type="text" id="nombre3" class="cajaMedia" value="<?echo $registro[2]?>" onfocus="calculaTotal(this)" readonly style="text-align:right"></td>								
						</tr>	
						-->
					</table>
					</form>
					</div>
					<input name="codarticulo" value="<? echo $codarticulo?>" type="hidden" id="codarticulo">
				</div><!--Fin de Busqueda2-->
				</br>
				<div id="frmBusqueda2">
					<form id="formulario_lineas1" name="formulario_lineas1" method="post" action="frame_lineas.php" target="frame_lineas">					
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabObsDespachos" minimo=1 columnas=1 nrot=6>
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='6' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=1; //nro de filas
						if($cant>0){$fila=mysql_result($rs_lineas,0,"fila_liq");
							$columna=mysql_result($rs_lineas,0,"columna_liq");
							$valor=mysql_result($rs_lineas,0,"valor_liq");																								
															
						}?>																			
						<tr>
							<td width="1%">&nbsp;</td>
							<td width="99%"><b>Observaciones</b></td>								
						</tr>
						<tr>							
							<td width="1%">&nbsp;</td>	
							<?if($cant==0){?>
								<td width="99%"><textarea name="descDesp" id="descDesp" class="areatexto" rows="4" cols="130" wrap="virtual"></textarea></td>
							<?}else{?>						
								<td width="99%"><textarea name="descDesp" id="descDesp" class="areatexto" rows="4" cols="130" wrap="virtual"><?echo $valor?></textarea></td>
							<?}?>
						</tr>
					</table>	
					</form><!--Fin de formulario_lineas-->
				</div><!--Fin de Busqueda2-->								
				<br/>
				<div id="frmBusqueda2">
					<form id="formulario_total" name="formulario_total">					
						<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0 id="tabTotal" minimo=1 columnas=3 nrot=9>							
						<? $sel_lineas="SELECT fila_liq,columna_liq,valor_liq FROM liquidacionDetalles WHERE cod_liq='$codigo_liq' AND cod_tabla_liq='9' ORDER BY fila_liq,columna_liq ASC";
						$rs_lineas=mysql_query($sel_lineas);
						$cant=mysql_num_rows($rs_lineas);
						$registro=array();
						$nrof=0; //nro de filas
						if($cant>0){?>									
							<?for ($i = 0; $i < $cant; $i++) { 
								$fila=mysql_result($rs_lineas,$i,"fila_liq");
								$columna=mysql_result($rs_lineas,$i,"columna_liq");
								$valor=mysql_result($rs_lineas,$i,"valor_liq");																								
							
								if($fila==$nrof)
								{
									$registro[$columna-1]=$valor;									
								}
								else
								{	
									$i--;
								?>
									<tr>	
										<?if($fila==1){?>
											<td width="1%">&nbsp;</td>									
											<td width="80%"><b> <?echo $registro[0]?> </b></td>
											<td width="20%"><input name="total" type="text" class="cajaMedia" id="total" value="<?echo $registro[1]?>" disabled="disabled" style="text-align:right"></td>																																																
										<?}else{?>
											<td width="1%"><input type="checkbox" name="check_adelanto" id="check_adelanto" checked="checked" onclick="habilita_saldo()"/></td>
											<td width="80%"><b> <?echo $registro[0]?> </b></td>
											<td width="20%"><input name="adelanto" type="text" class="cajaMedia" id="adelanto" onkeyup="calculaSaldo(this)" value="<?echo $registro[1]?>" style="text-align:right"></td>																																																
										<?}?>
									</tr>
								<?
									$nrof++;								
									for($x=0;$x<4;$x++)													
										$registro[$x]="";	

								}
							}
							?>	
							<!--Para imprimir la ultima fila-->
							<?if($nrof==0){ //solo tiene total liquidacion?> 
								<tr>
									<td width="1%">&nbsp;</td>									
									<td width="80%"><b> <?echo $registro[0]?> </b></td>
									<td width="20%"><input name="total" type="text" class="cajaMedia" id="total" value="<?echo $registro[1]?>" disabled="disabled" style="text-align:right"></td>
								</tr>
								<tr>
									<td width="1%"><input type="checkbox" name="check_adelanto" id="check_adelanto" onclick="habilita_saldo()"/></td>
									<td width="81%"><b>TOTAL ADELANTO</b></td>													
									<td width="20%"><input NAME="adelanto" type="text" class="cajaMedia" id="adelanto" size="17" maxlength="17" onkeyup="calculaSaldo(this)" disabled="disabled" style="background-color:#72A4D2;text-align:right"></td>		
								</tr>
								<tr>
									<td width="1%">&nbsp;</td>
									<td width="81%"><b>TOTAL SALDO</b></td>													
									<td width="20%"><input NAME="saldo" type="text" class="cajaMedia" id="saldo" size="30" maxlength="30" disabled="disabled" style="background-color:#72A4D2;text-align:right"></td>		
								</tr>	
							<?}else{?>
								<tr>	
									<td width="1%">&nbsp;</td>									
									<td width="80%"><b> <?echo $registro[0]?> </b></td>
									<td width="20%"><input name="saldo" type="text" class="cajaMedia" id="saldo" value="<?echo $registro[1]?>" style="text-align:right"></td>																																																							
								</tr>	
							<?}?>
						<?}?>
					</table>	
					</form><!--Fin de formulario_lineas-->
				</div><!--Fin de Busqueda2-->							  								
				</div><!--fin de center-->
			</div><!--fin de contenido-->
		</div><!--fin de pagina-->
	</body>
</html>
